﻿using Gonte.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace MyUtilitiesTest
{
    /// <summary>
    ///This is a test class for FieldLengthValidatorTest and is intended
    ///to contain all FieldLengthValidatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FieldLengthValidatorTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void FieldLengthValidatorValidateNullFieldTest()
        {
            FieldLengthValidator validator = new FieldLengthValidator(10, 100);
            Assert.AreEqual(true, validator.Validate(null)); // This validator does not validate nulls
        }

        [TestMethod()]
        public void FieldLengthValidatorInvalidDataTest()
        {
            FieldLengthValidator validator = new FieldLengthValidator(10, 100);
            Assert.AreEqual(false, validator.Validate(10)); // Data must be of string field
            Assert.AreEqual("The type to validate against: System.String does not correspond with the type of the object: System.Int32", validator.Error);
        }

        [TestMethod()]
        public void FieldLengthValidatorValidateLessThanRangeFieldTest()
        {
            String str = "123456789";
            FieldLengthValidator validator = new FieldLengthValidator(10, 15);

            Assert.AreEqual(false, validator.Validate(str));
            Assert.AreEqual(typeof(String), validator.Type);
            Assert.AreEqual("Length of string: 9 is out of range [10, 15]", validator.Error);
        }

        [TestMethod()]
        public void FieldLengthValidatorValidateInRangeLowerBoundFieldTest()
        {
            String str = "1234567890";
            FieldLengthValidator validator = new FieldLengthValidator(10, 15);
            Assert.AreEqual(true, validator.Validate(str));
        }

        [TestMethod()]
        public void FieldLengthValidatorValidateInRangeUpperBoundFieldTest()
        {
            String str = "123456789012345";
            FieldLengthValidator validator = new FieldLengthValidator(10, 15);
            Assert.AreEqual(true, validator.Validate(str));
        }

        [TestMethod()]
        public void FieldLengthValidatorValidateGreaterThanRangeFieldTest()
        {
            String str = "1234567890123456";
            FieldLengthValidator validator = new FieldLengthValidator(10, 15);
            Assert.AreEqual(false, validator.Validate(str));
            Assert.AreEqual("Length of string: 16 is out of range [10, 15]", validator.Error);
        }
    }
}
